package controller

import (
	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/mvc"
	"fmt"
	"gomicro/httpJsonMicro/hjmClient/util"
	"context"
	"github.com/micro/go-micro/v2/client/selector"
	"github.com/micro/go-micro/v2/client"
	"github.com/micro/go-plugins/client/http/v2"
)

type MemberMicroController struct{
    Ctx  iris.Context
}

func (c *MemberMicroController) PostMicroinsert() mvc.Result {

	name := c.Ctx.FormValue("name")
	info := c.Ctx.FormValue("info")
	fmt.Println(name)

	httpMicroSelector := selector.NewSelector(
		selector.Registry(util.EtcdRegistry),
		selector.SetStrategy(selector.RoundRobin),
	)

	NewClient := http.NewClient(
		client.Selector(httpMicroSelector),
		client.ContentType("application/json"),
	)

	req := NewClient.NewRequest("go.httpmicro.api.member.server", "/insertall", map[string]string{"info" : info})
	var res map[string]interface{}
	NewClient.Call(context.Background(), req, &res)

	return mvc.Response{
		Object : res,
	}
}


func (c *MemberMicroController) PostMicroquery() mvc.Result {

	httpMicroSelector := selector.NewSelector(
		selector.Registry(util.EtcdRegistry),
		selector.SetStrategy(selector.RoundRobin),
	)

	NewClient := http.NewClient(
		client.Selector(httpMicroSelector),
		client.ContentType("application/json"),
	)

	req := NewClient.NewRequest("go.httpmicro.api.member.server", "/queryallinfo", map[string]interface{}{})
	var res interface{}
	NewClient.Call(context.Background(), req, &res)

	fmt.Println("返回结果：", res)
	return mvc.Response{
		Object : res,
	}
}


